import { Component, Host } from "@angular/core";
import { AccountService, PermissionTypeEnum } from "./account.service";
import { StorageService } from "../../shared/services/storage.service";
import { AppComponent } from "../../app.component";
import { AnalyticsService } from "../../shared/services/googleAnalytics.service";
import { GoogleAnalyticsBeacon } from "../../shared/models/googleAnalytics.model";

@Component({
    moduleId: module.id,
    templateUrl: 'account.component.html',
    styleUrls: ['account.component.scss']
})
export class AccountComponent{
    public researchProducts: any[];
    public features: any[];
    public managerName: string;
    public managerEmail: string;

    constructor(private accountService: AccountService,
        @Host() private rootComponent: AppComponent,
        private analyticsService: AnalyticsService){}

    ngOnInit(){
        this.analyticsService.sendBeacon(new GoogleAnalyticsBeacon('Landing Page', 'Your Account', { }));
        //get accountid
        let userInfo = StorageService.get().userInfo;
        this.managerName = userInfo.accountManagerName;
        this.managerEmail = userInfo.accountManagerEmail;
        this.rootComponent.finishLoading();
        
        //get research products
        this.accountService.getAccountPermissions(userInfo.accountId, PermissionTypeEnum.ResearchProduct).subscribe(data=>{
            this.researchProducts = data;
        });


        //get features
        this.accountService.getAccountPermissions(userInfo.accountId, PermissionTypeEnum.Features).subscribe(data=>{
            this.features = data;
        });


      /*   this.accountService.getProductPermission(userInfo.accountId,  "Product Involvement").subscribe(data=>{
        });

        this.accountService.getProductPermission(userInfo.accountId,  "Global Compact").subscribe(data=>{
        }); */
    }
}